from openai import OpenAI

# Initialize the OpenAI client
client = OpenAI(
    api_key="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")

# Initialize messages with a system prompt
messages = [{"role": "system", "content": "You are a helpful assistant."}]

while True:
    # Read the next prompt from the user
    user_input = input("You: ")

    # Exit the loop if the user types 'exit'
    if user_input.lower() == 'exit':
        print("Exiting the chat.")
        break

    # Add the user's input to the message history
    messages.append({"role": "user", "content": user_input})

    # Create a chat completion
    completion = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages
    )

    # Get the assistant's response
    assistant_response = completion.choices[0].message.content

    # Print the assistant's response
    print("Assistant:", assistant_response)

    # Add the assistant's response to the message history
    messages.append({"role": "assistant", "content": assistant_response})

